<template>
  <el-table :data="tableData" style="width: 100%">
    <el-table-column prop="number" label="试题编号" width="120">
    </el-table-column>
    <el-table-column prop="subject" label="学科" width="120">
    </el-table-column>
    <el-table-column prop="catalog" label="目录 " width="120">
    </el-table-column>
    <el-table-column prop="questionType" label="题型">
      <template #default="{ row }">
        {{
          row.questionType == 1
            ? "单选"
            : row.questionType == 2
            ? "多选"
            : "简单"
        }}
      </template>
    </el-table-column>
    <el-table-column prop="question" label="题干" width="200">
      <template #default="{ row }">
        <p v-html="row.question"></p>
      </template>
    </el-table-column>
    <el-table-column prop="addDate" label="录入时间" width="200">
    </el-table-column>
    <el-table-column prop="difficulty" label="难度">
      <template #default="{ row }">
        {{
          row.difficulty == 1 ? "简单" : row.difficulty == 2 ? "一般" : "困难"
        }}
      </template>
    </el-table-column>
    <el-table-column prop="creator" label="录入人" width="120">
    </el-table-column>
    <el-table-column prop="chkState" label="审核状态" width="120">
    </el-table-column>
    <el-table-column prop="chkRemarks" label="审核意见" width="120">
    </el-table-column>
    <el-table-column prop="chkUser" label="审核人" width="120">
    </el-table-column>
    <el-table-column prop="creator" label="发布状态" width="120">
    </el-table-column>
    <el-table-column
      prop="address"
      label="操作"
      width="200"
      fixed="right"
      align="center"
    >
      <template #default="{ row }">
        <el-button type="text" size="small" @click="openDetail(row)"
          >预览</el-button
        >
        <el-button
          type="text"
          size="small"
          @click="openCheck(row)"
          :disabled="row.chkState == 1 || row.chkState == 2"
          >审核</el-button
        >
        <el-button
          type="text"
          size="small"
          @click="$router.push({ path: '/questions/new' })"
          >修改</el-button
        >
        <el-button
          type="text"
          size="small"
          @click="choicePublish(row, 'pub')"
          >{{ row.publishState == 0 ? "上架" : "下架" }}</el-button
        >
        <el-button
          type="text"
          size="small"
          @click="delPublish(row, 'del')"
          :disabled="row.publishState === 1 ? true : false"
          >删除</el-button
        >
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
import { choicePublish } from '@/api/hmmm/questions.js'
export default {
  props: {
    tableData: {
      type: [Array],
      required: true
    },
    centerDialogVisible: {
      type: [Boolean, String],
      required: true
    },
    checkDialogVisible: {
      type: [Boolean, String],
      required: true
    },
    OperateDialogVisible: {
      type: [Boolean, String],
      required: true
    },
    detailId: {
      type: [Number, String],
      required: true
    },
    type: {
      type: [String],
      required: true
    },
    publish: {
      type: [String],
      required: true
    }
  },
  name: 'questionTable',
  data () {
    return {
      form: {
        page: 1,
        pagesize: 5,
        subjectID: '',
        difficulty: '',
        questionType: '',
        tags: '',
        province: '',
        city: '',
        keyword: '',
        remarks: '',
        shortName: '',
        direction: '',
        catalogID: '',
        creatorID: ''
      }
    }
  },
  methods: {
    // 打开试题详情弹出框
    openDetail (row) {
      this.$emit('update:centerDialogVisible', true)
      this.$emit('update:detailId', row.id)
    },
    // 打开审核弹出框
    openCheck (row) {
      this.$emit('update:checkDialogVisible', true)
      this.$emit('update:detailId', row.id)
    },
    // 上架下架操作
    async choicePublish (row, type) {
      this.$emit('update:OperateDialogVisible', true)
      this.$emit('update:detailId', row.id)
      this.$emit('update:type', type)
      this.$emit('update:publish', row)
    },
    // 删除精选题目
    delPublish (row, type) {
      this.$emit('update:OperateDialogVisible', true)
      this.$emit('update:detailId', row.id)
      this.$emit('update:type', type)
    }
  }
}
</script>

  <style scoped lang='less'></style>
